package com.aidansmeaton;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.widget.Toast;

public class LogoutActivity extends WebViewActivity {
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		url = "http://www.airwaysim.com/Logout";
		loadWebView();
				
	}
	
	@Override
	protected void loadWebView() {
				
		webview = new WebView(myApp);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.addJavascriptInterface(new LoginJavaScriptInterface(), "HTMLOUT");
		webview.getSettings().setSaveFormData(true);
		webview.getSettings().setBuiltInZoomControls(true);
		webview.setWebViewClient(new LoginWebViewClient());
		webview.loadUrl(url); // 'html' instance variable is also loaded here
		
	}
	
	private void login() {
		Intent i = new Intent(getBaseContext(), LoginActivity.class);
        startActivity(i);
        finish();
	}
	
	/* An instance of this class will be registered as a JavaScript interface */
	protected class LoginJavaScriptInterface	{
		
	    public void showHTML(String pageHTML) {
	    	login();
	    }
	}
	
	private class LoginWebViewClient extends HTMLWebViewClient {
		
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			Toast.makeText(getApplicationContext(), "LogoutActivity: " + url, Toast.LENGTH_LONG).show();
			view.loadUrl(url);  
			return true;
		}
		
	}
		
}